
#ifndef _SEMAPHORE_H
#define _SEMAPHORE_H_

#include <stdio.h>
#include "queue.h"

typedef struct sem_t{
	int count;
	int size;
	list q;
}semaphore;

/* reference to the brain10 ready queue
 * that should be used for semaphores. This
 * has to be set in the VM after the header
 * inclusion.
 */
list* process_ready_queue;

/*
 * Call wait() on a semaphore. The count is
 * first decremented, then if the count is less
 * than 0, that process is added to the semaphore
 * queue from the brain10 VMs ready queue
 * @param sem A semaphore to decrement
 */
int wait(semaphore* sem);

/*
 * Call signal() on a semaphore. The count is
 * first incremented, then if the count is >= 0,
 * the next process waiting in line is removed from the
 * queue and allowed to continue its execution.
 * @param sem A semaphore to increment
 */
void sig(semaphore* sem);

/*
 * Set the count of the semaphore
 * @param sem A semaphore
 * @param value The new value of the semaphore's count
 */
void initialize(semaphore* sem, int value);

/*
 * print out the processes currently waiting in a
 * semaphore's queue
 * @param sem The semaphore's queue to use
 */
void printSemaphore(semaphore* sem);


#endif /* SEMAPHORE_H_ */
